/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package EJB.Business;

import java.util.Date;
import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import java.sql.Timestamp;
import Entity.Reserva;
import Entity.Pedido;
import EJB.Entity.ReservaFacade;
import EJB.Entity.ReservaFacadeLocal;

import javax.ejb.EJB;

/**
 *
 * @author Aldo
 */
@Stateful
public class GestorDeReserva implements GestorDeReservaLocal {
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    private Reserva reserva;
    private List<Pedido> pedidos;
    private @EJB ReservaFacadeLocal rfacade;
    private boolean created;

    public GestorDeReserva(){
        reserva = new Reserva();;
        rfacade = new ReservaFacade();
        created = false;
    }

    public void update(){
        if(created)
            rfacade.edit(reserva);
        else{
            Timestamp actual = new Timestamp(new Date().getTime());
            reserva.setFechaCreacion(actual);
            rfacade.create(reserva);
            created = true;
        }
    }

    public void asignarFecha(Date fecha){
        reserva.setFechaObjetivo(fecha);     
    }

    public void agregarPedido(Pedido p){
        pedidos.add(p);
        reserva.setPedidos(pedidos);
    }

    public Reserva getReserva(){
        return reserva;
    }

    public List<Pedido> mostrarPedidos(){
        return pedidos;
    }
    
    @Remove
    public void terminar() {}
 
}
